<template>
  <el-dialog
    title="班级列表"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="70%"
  >
    <el-row class="JADP-common-search-box" :gutter="16">
      <el-form @submit.native.prevent>
        <el-col :span="6">
          <el-form-item label="试卷名称">
            <el-input
              v-model="query.testpapername"
              placeholder="请输入"
              clearable
            >
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="search()"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh-right" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>

    <JADP-table
      v-loading="loading"
      :data="list"
      @sort-change="sortChange"
      highlight-current-row
      @current-change="handleCurrentChange"
      :row-style="{ cursor: 'pointer' }"
    >
      <el-table-column
        prop="testpapername"
        label="试卷名称"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column label="分类" prop="classification" algin="left" />
      <el-table-column prop="testpapertype" label="试卷类型" align="left" />
      <el-table-column prop="questionmethod" label="出题方式" align="left" />
      <el-table-column prop="releasestatus" label="发布状态" align="left" />
    </JADP-table>

    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="initData"
    />

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "clazztable",
  data() {
    return {
      visible: false,
      loading: false,
      query: {
        testpapername: undefined,
        releasestatus: "6d5c2898dfb84a20a8afcb70fecef9ef"
      },
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      list: [],
      currentRow: null
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.loading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/testPaperManage/Xy_ks_examination_paper`,
        method: "get",
        data: query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.loading = false;
      });
    },

    handleCurrentChange(val) {
      console.log(val);
      this.currentRow = val;
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    },
    dataFormSubmit() {
      if (!this.currentRow) {
        return this.$message.warning("请至少选择一张试卷");
      }
      this.$emit("currentRow", this.currentRow);
      this.visible = false;
    }
  }
};
</script>
<style scoped lang="scss"></style>
